<?php

namespace Core\Utils\Ip;

class Ipinit
{
    public $ip;
    public function __construct(){
        $unknown = 'unknown';
        if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && $_SERVER['HTTP_X_FORWARDED_FOR'] && strcasecmp($_SERVER['HTTP_X_FORWARDED_FOR'], $unknown)) {
            $this->ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
        } elseif (isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], $unknown)) {
            $this->ip = $_SERVER['REMOTE_ADDR'];
        }
        if (false !== strpos($this->ip, ',')) {
            $array = explode(',', $this->ip);

            $this->ip = reset($array);
        }
    }
    public function __toString(){
        $this->ip = $this->ip ?:"139.205.189.196";
        return $this->ip;
    }
}